package com.tozed.android.launcher;

import com.tozed.android.launcher.R;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class HomeEditViewItem extends LinearLayout {

    private ImageButton homeImage = null;
    private ImageView workspaceView = null;
    private boolean isDefault = false;
    private defalutPagechangeListener mListener;
    private boolean mIsEmpty = true;

    public static HomeEditViewItem getAddView(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        HomeEditViewItem workspace_layout = (HomeEditViewItem) inflater.inflate(R.layout.workspace_edit_item, null);
        workspace_layout.homeImage.setVisibility(GONE);
        workspace_layout.workspaceView.setImageResource(R.drawable.homescreen_quick_view_add);
        workspace_layout.setGravity(Gravity.CENTER);
        return workspace_layout;
    }

    public static HomeEditViewItem newInstance(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        HomeEditViewItem workspace_layout = (HomeEditViewItem) inflater.inflate(R.layout.workspace_edit_item, null);
        return workspace_layout;
    }

    public HomeEditViewItem(Context context) {
        super(context);
    }

    public HomeEditViewItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HomeEditViewItem(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        homeImage = (ImageButton) findViewById(R.id.homepage_indicator);
        workspaceView = (ImageView) findViewById(R.id.workspace_image);

        homeImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isDefault) return;
                if (mListener != null) {
                    mListener.onDefaultPageChanged(HomeEditViewItem.this);
                }
            }
        });

    }

    public void setDefault(boolean value) {
        isDefault = value;
        homeImage.setImageResource(
                value ? R.drawable.model_set_btn_select : R.drawable.model_set_btn_normal);
        this.setBackgroundResource(
                value ? R.drawable.home_pinch_view_bg_selected : R.drawable.home_pinch_view_bg);
    }

    public void setDefaultChangeListener(defalutPagechangeListener listener) {
        mListener = listener;
    }

    public interface defalutPagechangeListener {
        public void onDefaultPageChanged(HomeEditViewItem view);
    }

    public boolean isDefault() {
        return isDefault;
    }

    public void setCellEmpty(boolean isEmpty) {
        this.mIsEmpty = isEmpty;
    }

    public boolean isCellEmpty() {
        return mIsEmpty;
    }

}
